package cn.zhouyuxin.z99.controller;

import com.jfinal.core.Controller;
import com.jfinal.kit.Base64Kit;

import cn.zhouyuxin.z99.model.User;

public class LoginController extends Controller {
	private User user=new User();
	public void index() {
		this.render("login.html");
	}
	
	public void login() {
		user = this.user
				.findFirst("select * from `user` where ( `user` = '" + this.getPara("useroremail") + "' or `email` = '"
						+ this.getPara("useroremail") + "') and `password` = '" + Base64Kit.encode(this.getPara("password")) + "'");
		if(user != null) {
			this.setSessionAttr("usersession",user);
			this.redirect("/admin");
		}else {
			//this.redirect("/admin/login");
			this.renderHtml("<script type=\"text/javascript\"> alert(\"用户信息或密码错误请重新登录\");window.history.back();</script>");
		}
	}
}